package com.dnzx.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.dnzx.framework.page.PageResult;
import org.springframework.stereotype.Service;

import com.dnzx.dao.ICategoryDao;
import com.dnzx.model.CategoryBO;
import com.dnzx.service.ICategoryService;

/**
 * 商品分类
 */
@Service
public class CategoryServiceImpl implements ICategoryService {

    @Resource
    private ICategoryDao categoryDao;

    @Override
    public void save(CategoryBO categoryBO) throws Exception {
        this.categoryDao.save(categoryBO);
    }

    @Override
    public void delete(Long id) throws Exception {
        this.categoryDao.delete(id);
    }

    @Override
    public void update(CategoryBO categoryBO) throws Exception {
        this.categoryDao.update(categoryBO);
    }
    
    @Override
    public CategoryBO get(Long id) {
        return this.categoryDao.get(id);
    }
    
    @Override
	public CategoryBO get(CategoryBO categoryBO) {
    	List<CategoryBO> categoryBOList = this.categoryDao.queryList(categoryBO);
    	if (categoryBOList != null && categoryBOList.size() > 0) {
    		return categoryBOList.get(0);
    	}
		return null;
	}
    
    @Override
    public List<CategoryBO> queryList(CategoryBO categoryBO) {
        return this.categoryDao.queryList(categoryBO);
    }

    @Override
    public PageResult<List<CategoryBO>> queryPage(CategoryBO categoryBO, PageResult<List<CategoryBO>> pageResult) {
    	int totalRows = this.categoryDao.queryCount(categoryBO);
    	pageResult.setTotalRows(totalRows);
    	pageResult.setCurrentPage(categoryBO.getCurrentPage());
    	pageResult.setPageSize(categoryBO.getPageSize());
    	List<CategoryBO> records = this.categoryDao.queryPage(pageResult.getPageSize(), pageResult.getStartRow(), categoryBO);
    	pageResult.setT(records);
    	return pageResult;
    }

}
